<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="order by dede58.com"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="img/logo.png"/>
    <title>业财税一体化平台</title>
    <link href="css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" href="css/mmss.css"/>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <!--[if lt IE 9]>
    <script src="js/html5shiv.min.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    <style>

    </style>
</head>
<body>
<div id="app">
    <header>
        <div class="container-fluid navbar-fixed-top bg-primary">
            <ul class="nav navbar-nav  left">
                <li class="text-white h4">
                    &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-leaf"></span>&nbsp;&nbsp;<b>业财税一体化平台</b>
                </li>
            </ul>
            <ul class="nav navbar-nav nav-pills right ">
                <li class="bg-info dropdown">
                    <a class="dropdown-toggle" href="#" data-toggle="dropdown">
                        <span class="glyphicon glyphicon-user"></span>&nbsp;<span>{{token.userName}}</span><span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-right">
                        <li class="text-center"><a v-on:click="logout()"><span class="text-primary">退出</span></a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </header>

    <section>
        <div class="container-fluid">
            <div class="row ">
                <!--左侧导航开始-->
                <div class="col-xs-2 bg-blue">
                    <br/>
                    <div class="panel-group sidebar-menu" id="accordion" aria-multiselectable="true">
                        <div class="panel panel-default menu-first menu-first-active">
                            <a data-toggle="collapse" data-parent="#accordion" href="index.html" aria-expanded="true"
                               aria-controls="collapseOne">
                                <i class="icon-home icon-large"></i> 主页
                            </a>
                        </div>
                        <div class="panel panel-default menu-first">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true"
                               aria-controls="collapseOne">
                                <i class="icon-user-md icon-large"></i> 系统管理</a>
                            </a>

                            <div id="collapseOne" class="panel-collapse collapse " >
                                <ul class="nav nav-list menu-second">
                                    <li v-if="token.role == 'admin'"><a href="user_manage.html"><i class="icon-user"></i> 用户管理</a></li>
                                    <li v-if="token.role == 'admin'"><a href="admin_manage.html"><i class="icon-user"></i> 管理员管理</a></li>
                                    <li v-if="token.role == 'user'"><a href="business_line_manage.html"><i class="icon-list"></i> 业务线管理</a></li>
                                    <li v-if="token.role == 'user'"><a href="tax_rate_manage.html"><i class="icon-list"></i> 区域税率管理</a></li>
                                    <li v-if="token.role == 'user'"><a href="company_account_manage.html"><i class="icon-list"></i> 公司账户管理</a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="panel panel-default menu-first" v-if="token.role == 'user'">
                            <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"
                               aria-expanded="false" aria-controls="collapseTwo">
                                <i class="icon-book icon-large"></i> 账务管理</a>
                            </a>
                            <div id="collapseTwo" class="panel-collapse collapse">
                                <ul class="nav nav-list menu-second">
                                    <li><a href="contract_manage.html"><i class="icon-list"></i> 合同管理</a></li>
                                    <li><a href="invoice_manage.html"><i class="icon-list"></i> 发票管理</a></li>
                                    <li><a href="receivable_accrued_manage.html"><i class="icon-list"></i> 应收计提</a></li>
                                    <li><a href="receivable_bill_manage.html"><i class="icon-list"></i> 应收账单</a></li>
                                    <li><a href="payable_accrued_manage.html"><i class="icon-list"></i> 应付计提</a></li>
                                    <li><a href="payable_bill_manage.html"><i class="icon-list"></i> 应付账单</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <!--左侧导航结束-->
                <!----------------------------------------------------------------------------------------------------->
                <!--右侧内容开始-->
                <div class="col-xs-10">
                    <br/>
                    <ol class="breadcrumb">
                        <li class="active">财务管理 - 应收账单</li>
                    </ol>

                    <div class="input-group line left">
                        <span class="input-group-addon" ><span class="glyphicon glyphicon-search"></span></span>
                        <input type="number" id="selectContractId" class="form-control" placeholder="合同ID" aria-describedby="basic-addon2">
                    </div>
                    <div class="input-group line left">
                        <span class="input-group-addon" ><span class="glyphicon glyphicon-search"></span></span>
                        <input type="number" id="selectReceivableAccruedId" class="form-control" placeholder="计提ID" aria-describedby="basic-addon2">
                    </div>
                    <div class="input-group line left">
                        <span class="input-group-addon"><span class="glyphicon glyphicon-search"></span></span>
                        <input type="number" id="selectBillId" class="form-control" placeholder="账单ID" aria-describedby="basic-addon2">
                    </div>
                    <a v-on:click="select()" class=" btn btn-primary "><span class="glyphicon glyphicon-search"></span></a>
                    <a v-on:click="" class="btn btn-primary " data-toggle="modal" data-target="#add">添加</a>
                    <table class="table table-bordered table-striped text-center bg-info">
                        <thead >
                        <tr class="info">
                            <th class="text-center" width="10%">ID</th>
                            <th class="text-center" width="10%">合同ID</th>
                            <th class="text-center" width="10%">计提ID</th>
                            <th class="text-center" width="10%">账单金额</th>
                            <th class="text-center" width="10%">付款公司</th>
                            <th class="text-center" width="10%">收款公司</th>
                            <th class="text-center" width="10%">创建时间</th>
                            <th class="text-center" width="10%">账单阶段</th>
                            <th class="text-center" width="10%">操作</th>
                        </tr>
                        </thead>
                        <br/><br/>
                        <tbody>
                        <tr v-for="item in list">
                            <td v-text="item.id"></td>
                            <td v-text="item.contractId"></td>
                            <td v-text="item.receivableAccruedId"></td>
                            <td v-text="item.billAmount"></td>
                            <td v-text="item.payableCompanyName"></td>
                            <td v-text="item.receivableCompanyName"></td>
                            <td v-text="item.createTime"></td>
                            <td v-text="item.billOperationStatusName"></td>
                            <td>
                                <a v-on:click="confirm(item)" v-if="item.billOperationStatusValue == 1" class="btn btn-primary btn-sm">确认</a>
                                <a v-on:click="edit(item)" v-if="item.billOperationStatusValue == 2" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#edit">勾稽</a>
                                <!--                                <a v-on:click="edit(item)" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#edit">编辑</a>-->
                                <a v-on:click="deleteOne(item.id)" class="btn btn-primary btn-sm" >删除</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <ul class="pagination right">
                        <li><a v-on:click="lastPage()" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
                        <li class="active"><a href="#">{{currentPage}} <span class="sr-only">{{currentPage}}</span></a></li>
                        <li><a v-on:click="nextPage()" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
                    </ul>
                    <!----------------------------------------------------------    ------------------------------------------->
                </div>
                <!--右侧内容结束-->
            </div>
        </div>
    </section>
    <div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="add">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">添加</h4>
                </div>
                <div class="modal-body">
                    <ul>
                        <li>
                            <label><span>账单金额：</span></label>
                            <input v-model="addBillAmount" type="number" placeholder="预估金额"/>
                        </li>
                        <li>
                            <label><span>付款公司：</span></label>
                            <input v-model="addPayableCompanyName" type="text" placeholder="付款公司"/>
                        </li>
                        <li>
                            <label><span>收款公司：</span></label>
                            <input v-model="addReceivableCompanyName" type="text" placeholder="收款公司"/>
                        </li>
                    </ul>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary btn-sm" v-on:click="addOne()">添加</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">勾稽</h4>
                </div>
                <div class="modal-body">
                    <ul>
                        <li>
                            <label><span>勾稽计提：</span></label>
                            <input v-model="editPayableAccruedId" type="number" placeholder="计提ID"/>
                        </li>
                    </ul>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary btn-sm" v-on:click="saveOne()">勾稽</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="js/jquery-1.11.3.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/vue.dev.js"></script>
<script>
    var v = new Vue({
        el: "#app",
        data:{
            token:{id:1,role:"user",userName:"guoyuhang"},
            pageInfo:{},
            currentPage: 1,
            list: [],
            item: {},
            selectContractId:-1,
            selectReceivableAccruedId:-1,
            selectBillId:-1,
            addBillAmount:"",
            addPayableCompanyName:"",
            addReceivableCompanyName:"",
            editPayableAccruedId:"",
        },
        created: function (){
            var self = this;
            this.token = JSON.parse(localStorage.getItem("token"));
            if (this.token == null){
                alert("未登录");
                window.location.href='login.html';
            }
            console.log(this.selectReceivableAccruedId,this.selectContractId);
            $.ajax({
                url: "http://localhost:8083/receivable/receivable/bill/get/all/receivable/bill",
                type: "POST",
                dataType: "json",
                data: {
                    "contractId": this.selectContractId,
                    "accruedId": this.selectReceivableAccruedId,
                    "billId": this.selectBillId,
                    "currentPage": this.currentPage
                },
                success: function (data){
                    self.list = data.result.list;
                    self.pageInfo = data.result;
                },
                error: function (data){

                }
            });
        },
        methods: {
            addOne: function (){
                console.log(this.addSettlementAmount);
                $.ajax({
                    url: "http://localhost:8083/receivable/receivable/bill/create/one/receivable/bill",
                    type: "POST",
                    dataType: "json",
                    data: {
                        "billAmount": this.addBillAmount,
                        "payableCompanyName": this.addPayableCompanyName,
                        "receivableCompanyName": this.addReceivableCompanyName
                    },
                    success: function (data){
                        alert(data.result);
                        window.location.href="receivable_bill_manage.html";
                    },
                    error: function (data){
                        window.location.href="receivable_bill_manage.html";
                    }
                });
            },
            deleteOne: function (id){
                var flag = confirm("是否删除");
                if (flag == false){
                    return;
                }
                $.ajax({
                    url: "http://localhost:8083/receivable/receivable/bill/delete/one/receivable/bill",
                    type: "POST",
                    dataType: "json",
                    data: {
                        "id": id
                    },
                    success: function (data){
                        alert(data.result);
                        window.location.href="receivable_bill_manage.html";
                    },
                    error: function (data){
                        window.location.href="receivable_bill_manage.html";
                    }
                });
            },
            edit: function (item){
                this.item = JSON.parse(JSON.stringify(item));
            },
            confirm: function (item){
                this.item = item;
                $.ajax({
                    url: "http://localhost:8083/receivable/receivable/bill/compile/one/receivable/bill",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json",
                    data: JSON.stringify(item),
                    success: function (data){
                        alert(data.result);
                        window.location.href="receivable_bill_manage.html";
                    },
                    error: function (data){

                    }
                });
            },
            saveOne: function (){
                this.item.receivableAccruedId = this.editPayableAccruedId;
                $.ajax({
                    url: "http://localhost:8083/receivable/receivable/bill/compile/one/receivable/bill",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json",
                    data: JSON.stringify(this.item),
                    success: function (data){
                        alert(data.result);
                        window.location.href="receivable_bill_manage.html";
                    },
                    error: function (data){
                        window.location.href="receivable_bill_manage.html";
                    }
                });
            },
            select: function (){
                var self = this;
                this.currentPage = 1;
                this.selectContractId = document.getElementById("selectContractId").value;
                this.selectReceivableAccruedId = document.getElementById("selectReceivableAccruedId").value;
                this.selectBillId = document.getElementById("selectBillId").value;
                console.log(this.selectReceivableAccruedId,this.selectBillId);
                $.ajax({
                    url: "http://localhost:8083/receivable/receivable/bill/get/all/receivable/bill",
                    type: "POST",
                    dataType: "json",
                    data: {
                        "contractId": this.selectContractId,
                        "accruedId": this.selectReceivableAccruedId,
                        "billId": this.selectBillId,
                        "currentPage": this.currentPage
                    },
                    success: function (data){
                        self.list = data.result.list;
                        self.pageInfo = data.result;
                    },
                    error: function (data){

                    }
                });
            },
            lastPage: function (){
                var self = this;
                if (self.currentPage === self.pageInfo.firstPage){
                    alert("已经是第一页");
                    return;
                }
                self.currentPage = self.currentPage - 1;
                console.log(this.selectReceivableAccruedId,this.selectBillId);
                $.ajax({
                    url: "http://localhost:8083/receivable/receivable/bill/get/all/receivable/bill",
                    type: "POST",
                    dataType: "json",
                    data: {
                        "contractId": this.selectContractId,
                        "accruedId": this.selectReceivableAccruedId,
                        "billId": this.selectBillId,
                        "currentPage": this.currentPage
                    },
                    success: function (data){
                        self.list = data.result.list;
                        self.pageInfo = data.result;

                    },
                    error: function (data){

                    }
                });
            },
            nextPage: function (){
                var self = this;
                if (self.currentPage === self.pageInfo.lastPage){
                    alert("已经是最后一页");
                    return;
                }
                self.currentPage = self.currentPage + 1;
                console.log(this.selectReceivableAccruedId,this.selectBillId);
                $.ajax({
                    url: "http://localhost:8083/receivable/receivable/bill/get/all/receivable/bill",
                    type: "POST",
                    dataType: "json",
                    data: {
                        "contractId": this.selectContractId,
                        "accruedId": this.selectReceivableAccruedId,
                        "billId": this.selectBillId,
                        "currentPage": this.currentPage
                    },
                    success: function (data){
                        self.list = data.result.list;
                        self.pageInfo = data.result;
                    },
                    error: function (data){

                    }
                });
            },
            logout: function (){
                localStorage.clear();
                window.location.href='login.html';
            }
        }
    });
</script>
</html>